<?php

/*
 * Camelot PHP Tools
 *
 * @version 2.0
 * @author Bendsoft
 * @package PHP Tools
 * @subpackage Camelot
 * @license FreeBSD License (www.bendsoft.com/licensing/)
 * 
 */

/**
 * Class with methods to execute Non Queries and static methods in a wcf service
 *
 * @author Bendsoft
 */
class SharePointNonQuery extends CamelotExceptionHandling {

    /**
     * Constructor
     *
     * @param Array $args
     */
    function __construct($args) {
        
        // Determine what kind of argument that is sent to the constructor
        // If we have an array we must convert this to a typed command for backwards compatibility
        if (is_array($args)) {
            $command = new SharePointNonQueryCommand();
            $command->buildCommandFromArray($args);
        } elseif ($args instanceof SharePointNonQueryCommand) {
            $command = $args;
        } else {
            $this->exception = new CamelotException(null, 408);
            $this->commandStatus = false;
            return;
        }

        // Validate the command using the internal validate method of the class
        $validateResult = $command->isValid();
        if ($validateResult !== true) {
            $this->exception = $validateResult;
            $this->commandStatus = false;
            return;
        }

        // Execute the command
        $commandResult = $command->execute();

        if ($commandResult instanceof CamelotException) {
            $this->exception = $commandResult;
            $this->commandStatus = false;

            // Throw CamelotException
            if (!SILENT_EXCEPTIONS) {
                throw $commandResult;
            }
        } else {
            $this->exception = null;
            $this->commandStatus = true;
            $this->CamelotSoap = $commandResult;
        }

        return;
    }

    /**
     * Executes a scalar query using the ExecuteScalar method in the wsdl service
     * connected to SharePoint and returns the first column of the first row in
     * the result set returned by the query. Additional columns or rows are ignored
     *
     * @param Array $args
     * @return String|Boolean
     */
    private function execute_scalar($args) {
        $this->_result = $this->client->ExecuteScalar($args)->ExecuteScalarResult;
    }

    /**
     * Destroy stuff when we are done with the class
     */
    function __destruct() {
        
    }

}

?>
